﻿using Blog190311.Areas.Back.Models.DAL;
using Blog190311.Models.DBModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Blog190311.Areas.Back.Controllers
{
    [Authorize]
    public class MessageController : Controller
    {
        MessageService messageService = new MessageService();
        // GET: Back/Message
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 多条件分页查询
        /// </summary>
        /// <param name="limit"></param>
        /// <param name="page"></param>
        /// <param name="name"></param>
        /// <param name="State"></param>
        /// <returns></returns>
        public ActionResult GetMessagesByPage(int limit, int page, string name, string state)
        {
            List<Message> lists = messageService.GetMessagesByPage(limit, page, name, state);
            int num = messageService.GetCount(name, state);
            return Json(new { code = 0, msg = "", count = num, data = lists }, JsonRequestBehavior.AllowGet);
        }

        public ActionResult UpdateMessage(Message messages)
        {
            int num = messageService.UpdateMessage(messages);
            return Content(num.ToString());
        }
        public ActionResult Edit(int id)
        {
            Message messages = messageService.GetMessagesById(id);
            return View(messages);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult DelMessage(int id)
        {
            int num = messageService.DelMessage(id);
            return Content(num.ToString());
        }
    }
}